home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / lack.zoo / gemlib / aes.c next >
Encoding:
C/C++ Source or Header  |  1993-11-07  |  2.2 KB  |  85 lines

  1. /*
  2.  * Common part of gemlib bindings
  3.  *
  4.  *    ++jrb    bammi@cadence.com
  5.  *    modified: mj -- ntomczak@vm.ucs.ualberta.ca
  6.  */
  7. #define __IN_COMMON_C
  8. #include "common.h"
  9.  
  10. /* 
  11.  * the common interface to aes 
  12.  *    int __aes__(coded control);
  13.  *    unsigned long coded control;
  14.  * coded control: (1 byte for each element of control in the long)
  15.  *    DD CC BB AA
  16.  * DD : aes opcode
  17.  * CC : sizeof _int_in
  18.  * BB : sizeof _int_out
  19.  * AA : sizeof _addrin
  20.  *
  21.  * Note: sizeof _addrout is needed only for rsrc_gaddr and is special
  22.  *     cased below.
  23.  *
  24.  * output: the value (int)_intout[0]
  25.  */
  26.  
  27. #ifdef __OLD__
  28. int __aes__(unsigned long coded_control)
  29. {
  30.     register unsigned char  *p = (unsigned char *)&coded_control;
  31.     register unsigned short *q = &_control[0];
  32.     
  33.     /* decode control */
  34.     do
  35.     {
  36.     *q++ = (unsigned short)(*p++);
  37.     } while(q < &_control[4]);
  38.     
  39.     /* only rsrc_gaddr() needs this */
  40.     *q = (_control[0] == 112) ? 1 : 0;
  41.     
  42.     /* call aes */
  43.     __asm__ volatile 
  44.     ("     movl    %0,    d1
  45.         movw    #0xc8, d0
  46.         trap    #2"
  47.      :                /* no outputs */
  48.      : "g"(&_aesparams[0])    /* inputs     */
  49.      : "d0", "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */
  50.      );
  51.     return (int)_int_out[0];
  52. }
  53. #else
  54. extern int (*__aes__)(unsigned long coded_control);
  55. /* 
  56.  * new more efficient coding thanks to Thomas Koenig (UI0T@DKAUNI2.BITNET)
  57.  * "I made use here of the movep instruction for the 680xx, which transfers
  58.  * data from a data register to alternate bytes of memory. The odd
  59.  * address makes sure that these bytes are transferred to the lower half
  60.  * of the words."
  61.  */
  62. int _user_aes(unsigned long coded_control)
  63. {
  64.  
  65.     /* call aes */
  66.     __asm__ volatile
  67.     ("  movel    %1,  d1
  68.         moval    %0@, a0         | lea %0@, a0 seems to moval %0,a0 why???
  69.     moveq    #0,  d0
  70.     movepl    d0,  a0@(0)    | clear high bytes of control array
  71.         movepl    d1,  a0@(1)
  72.         movl    %0,   d1
  73.         movw    #0xc8,d0    | note -- no movq here, it sign extends
  74.         trap    #2
  75.     movl    %0,   __aesparams"
  76.      :                /* no outputs */
  77.      : "a"(_aesparams), "g"(coded_control)    /* inputs     */
  78.      : "d0", "d1", "a0"   /* clobbered regs */
  79.      );
  80.     __aes__=&_user_aes;
  81.     return (int)_int_out[0];
  82. }
  83.  
  84. #endif /* __OLD__ */
  85.